package org.example.controller;

import org.example.pojo.User;
import org.example.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class AppController {

    @Autowired
    AppService appService;

    @RequestMapping("app")
    public ModelAndView index(HttpSession session){
        ModelAndView modelAndView = new ModelAndView("index");
        User user = (User) session.getAttribute("user");
        modelAndView.addObject("user", user);
        modelAndView.addObject("battleData", appService.queryBattleData(user));
        return modelAndView;
    }

    @RequestMapping("app/battle")
    @ResponseBody
    public Map<String, Object> queryBattle(@RequestParam("user") String username) {
        return appService.queryBattle(username);
    }
}
